package com.lingnan.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lingnan.entity.po.JobFavorite;
import com.lingnan.entity.po.JobPosition;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface JobFavoriteMapper extends BaseMapper<JobFavorite> {
    
    /**
     * 查询求职者收藏的职位列表（带职位详情）
     */
@Select("SELECT jf.id as favoriteId, DATE_FORMAT(jf.created_at, '%Y-%m-%d %H:%i:%s') as favoriteTime, " +
        "jp.id, jp.title, jp.type, jp.salary_range, jp.location, " +
        "jp.description, jp.edu_requirement, jp.exp_requirement, " +
        "c.name as companyName, c.industry " +
        "FROM job_favorite jf " +
        "LEFT JOIN job_position jp ON jf.position_id = jp.id " +
        "LEFT JOIN company c ON jp.company_id = c.id " +
        "WHERE jf.seeker_id = #{seekerId} AND jp.status = 1 " +
        "ORDER BY jf.created_at DESC")
List<Map<String, Object>> selectFavoritePositionsWithDetails(@Param("seekerId") Long seekerId);


    
    /**
     * 检查是否已收藏
     */
    @Select("SELECT COUNT(1) FROM job_favorite WHERE seeker_id = #{seekerId} AND position_id = #{positionId}")
    int checkIfFavorited(@Param("seekerId") Long seekerId, @Param("positionId") Long positionId);

}